package boot3.service.impl;

import boot3.mapper.LivechatMapper;
import boot3.mapper.UserMapper;
import boot3.pojo.User;
import boot3.service.LivechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LivechatServiceImpl implements LivechatService {

    @Autowired
    LivechatMapper livechatMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public List<String> getLiveroomUsers(String chatroom_id) {
        return livechatMapper.getLiveroomUsers(chatroom_id);
    }

    @Override
    public boolean setLiveroomUsers(String chatroom_id, String user_id, String start_time) {
        return livechatMapper.setLiveroomUsers(chatroom_id, user_id, start_time);
    }

    @Override
    public boolean deleteLiveroomUsers(String user_id, String chatroom_id) {
        return livechatMapper.deleteLiveroomUsers(user_id, chatroom_id);
    }

    @Override
    public Boolean deleteAllUsers(String chatroom_id) {
        return livechatMapper.deleteAllUsers(chatroom_id);
    }

    @Override
    public List<User> getUsersName(String chatroom_id) {
        //先根据chatroom_id获取聊天室中所有用户的ID
        List<String> liveroomUsers = getLiveroomUsers(chatroom_id);
        List<User> users = new ArrayList<>();
        for (String user_id : liveroomUsers) {
          User user=new User();
          user.setUserID(user_id);
          user.setUserName(userMapper.getUserName(user_id));
          users.add(user);
        }
       return users;
    }
}
